using System;
using Microsoft.Pex.Framework;

namespace Benchmarks
{
    public class DummyClass
    {
        public void TestTry(object x)
        {
            try
            {
                if (x == null)
                    throw new Exception();
                Console.WriteLine("hi");
                throw new Exception();
            }
            catch (Exception)
            {
                Console.WriteLine("exception");
            }
        }

        public void TestLoop()
        {
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("hi");
            }
        }

        public void TestSwitch(int i)
        {
            switch (i)
            {
                case 1:case 100:
                    Console.WriteLine("1");
                    break;
                case 2:
                    Console.WriteLine("2");
                    break;
                default:
                    Console.WriteLine("default");
                    break;
            }
        }

        public void TestOr(object x, object y)
        {
            int j = 5;
            switch (j)
            {
                case 1:
                case 100:
                    Console.WriteLine("1");
                    break;
                case 2:
                    Console.WriteLine("2");
                    break;
                default:
                    Console.WriteLine("default");
                    break;
            }

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("hi");
            }

            if (x == null)
            {
                Console.WriteLine("1");
            }
            else
            {
                Console.WriteLine("2");
            }
        }

        public void TestAnd(object x, object y)
        {
            if (x != null && y != null)
            {
                Console.WriteLine("1");
            }
            Console.WriteLine("2");
        }

        public void TestNormal(object x, object y)
        {
            if (x == null)
                if (y != null)
                {
                    Console.WriteLine("1");
                }
            Console.WriteLine("2");
        }
    }

    [PexClass(typeof (DummyClass))]
    public partial class ConditionCoverageTest
    {
        [PexMethod]
        public void TestOr(object x, object y)
        {
            PexAssume.IsNotNull(x);
//            PexAssume.IsNotNull(y);
            new DummyClass().TestOr(x, y);
        }

        [PexMethod]
        public void TestAnd(object x, object y)
        {
            PexAssume.IsNotNull(x);
            new DummyClass().TestAnd(x, y);
        }

        [PexMethod]
        public void TestNormal(object x, object y)
        {
            PexAssume.IsNotNull(x);
            new DummyClass().TestNormal(x, y);
        }
    }
}